package mws;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;


import java.lang.reflect.Field;

import java.util.Properties;

@Data
@ConfigurationProperties(prefix = ExecutorProperties.PREFIX )
public class ExecutorProperties {

    public static final String PREFIX = "executor.mws.of";//"mws.Executor".toLowerCase(); // 这个 prefix 必须小写

    private String configName ;

    private String serverAddr;

//    private String username;
//
//    private String password;

//    private String encode;

    private String group = "DEFAULT";

//    private String fileExtension = "properties";

//    private int timeout = 3000;
//
//    private String maxRetry;
//
//    private String configLongPollTimeout;
//
//    private String configRetryTime;
//
//    private boolean enableRemoteSyncConfig = true;

//    private String endpoint;
//
//    private String namespace;
//
//    private String accessKey;
//
//    private String secretKey;

    private boolean refreshEnabled = true;

    public Properties asProperties(){

        Field[] declaredFields = this.getClass().getDeclaredFields();
        Properties ret = new Properties();
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            try {
                Object o = declaredField.get(this);
                if (o != null) {
                    ret.put(declaredField.getName(), declaredField.getType().cast(o));
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
        if(ret.isEmpty())
            return null;
       return ret;
    };

}
